/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * JPanelPasillo.java
 *
 * Created on 20/11/2012, 19:10:43
 */

package hotelinteligente.vista;

import java.awt.Graphics;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Iterator;

/**
 *
 * @author vero
 */
public class JPanelPasillo extends javax.swing.JPanel {

    private PisoDibujable piso;
    int x,y, x1, y1;
    private DispositivoDibujable seleccionado;

    /** Creates new form JPanelPasillo */
    public JPanelPasillo() {
        initComponents();
        initPiso();
        validate();
        repaint();
        addMouseListener(new MyMouseListener());
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(0, 0, 0));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 273, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    // End of variables declaration//GEN-END:variables

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if(piso != null)
            piso.draw(g);
    }

    public DispositivoDibujable getSelected(int x, int y) {
        if(this.piso != null) {
            for(Iterator<DispositivoDibujable> it = this.piso.getIteratorDispositivosDibujables(); it.hasNext();) {
                DispositivoDibujable device= it.next();
                if(device.isSelected(x, y))
                    return device;
            }
        }
        return null;
    }

    private void initPiso() {
        this.piso= new PisoDibujable("Primer Piso");
   }

    void refresh(Graphics graphics) {
        paint(graphics);
    }

    class MyMouseListener extends MouseAdapter {

        public void mousePressed(MouseEvent e) {
        }

        @Override
        public void mouseReleased(MouseEvent e) {
        }

        @Override
        public void mouseClicked(MouseEvent e) {
        }
    }

    public PisoDibujable getPiso() {
        return piso;
    }
}
